#include <iostream>
#include <string>
using namespace std;

struct Node {
	string val;
	Node* left = nullptr;
	Node* right = nullptr;
};
string sp, tgt;
int flag;
Node* H = nullptr;
void getTree(Node*& h)
{
	string cur;
	cin >> cur;
	if (cur == sp) return;
	h = new Node;
	h->val = cur;
	getTree(h->left);
	getTree(h->right);
}

bool isOperator(string op)
{
	return op == "+" || op == "-" || op == "*" || op == "/" || op == "(" || op == ")";
}

int getPriority(char op)
{
	switch (op)
	{
	case '(':
		return 1; break;
	case '+':
	case '-':
		return 2; break;
	case '*':
	case '/':
		return 3; break;
	default:
		return 0;
	}
}

string dfs(Node* node) {
	if (!node) return "";

	// 叶子节点
	if (!isOperator(node->val)) {
		if (stoi(node->val) < 0)
			return "(" + node->val + ")";
		return node->val;
	}

	string left = dfs(node->left);
	string right = dfs(node->right);

	int p = getPriority(node->val[0]);
	int pl = getPriority(node->left ? node->left->val[0] : '6');
	int pr = getPriority(node->right ? node->right->val[0] : '6');

	if (node->left && isOperator(node->left->val) && pl < p) {
		left = "(" + left + ")";
	}

	if (node->right && isOperator(node->right->val) &&
		(pr < p || (pr == p && (node->val == "-" || node->val == "/")))) {
		right = "(" + right + ")";
	}

	return left + node->val + right;
}
int main()
{
	cin >> sp;
	getTree(H);
	cout << dfs(H);
	return 0;
}

//#
//* - + + 12 # # -14 # # 3 # # / -400 # # / 30 # # * -10 # # 5 # # -62 # #
//
//#
//+ 1 # # * + -12 # #  - 13 # # / -400 # # * 10 # # / -30 # # + 10 # # 5 # # -62 # #
//
//#
//+ - + + -12.1 # # 14 # # 3 # # / 400 # # - 30 # # + 10 # # 5 # # 62.2 # #
//
//#
//* / * * 12 # # 14 # # 3 # # / 400.3 # # / 30 # # * 10 # # -5.4 # # 62 # #
//
//#
//+ - * + -12 # # 14.3 # # 3 # # / 400 # # + -30 # # / 10.01 # # 5 # # -62 # #
//
//#
//+ 1 # # * + 12 # # - 13.2 # # / -400 # # * -30.1 # # * 2 # # + 10 # # 5 # # 62 # #
//
//#
//+ - * + 12 # # 14.2 # # 3 # # / -400 # # / 30 # # / 10 # # -5 # # 62.4 # #
//
//#
//+ - * + 12 # # 14 # # -3 # # / -400.1 # # * 30 # # / -10 # # 5 # # -62 # #